package com.example.demo.service;

import com.example.demo.main.Goods;
import com.example.demo.main.GoodsExample;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.service.Imp.SelectSQLOfPagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SelectByGoodsImpl implements SelectSQLOfPagination {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> selectLimit(Integer index, Integer offset) {//index页码
        index = index * offset;
        return goodsMapper.selectLimit(index, offset);
    }

    @Override
    public Integer selectAllCount() {
        return goodsMapper.selectCount();
    }

    public List<Goods> selectByLikeByGoodsNameAndLimit(String str, Integer Index, Integer offset) {//index页码
        Index = Index * offset;
        str = "%" + str + "%";
        return goodsMapper.selectByLikeGoodsNameAndLimit(str, Index, offset);
    }

    public Goods selectById(Long id) {
        return goodsMapper.selectByPrimaryKey(id);
    }

    public Integer insertByGoods(Goods goods) {
        return goodsMapper.insertSelective(goods);
    }

    public Integer updateByGoods(Goods goods) {
        return goodsMapper.updateByPrimaryKeySelective(goods);
    }

    public List<Goods> selectByKindAndLimit(String kind, Integer Index, Integer offset) {//index页码
        Index = Index * offset;
        return goodsMapper.selectByKindAndLimit(kind, Index, offset);
    }

    public Integer selectCountByKind(String kind) {
        return goodsMapper.selectCountOfKind(kind);
    }

    public Integer selectCountByGoodsNameLike(String LikeGoodsName) {
        LikeGoodsName = "%" + LikeGoodsName + "%";
        return goodsMapper.selectCountOfGoodsNameLike(LikeGoodsName);
    }

    public Integer subCount(String name) {
        return goodsMapper.subCount(name);
    }
}
